package com.zw.yzk.kabu.mapper;

import com.zw.yzk.kabu.data.network.entity.ExhibitionListEntity;
import com.zw.yzk.kabu.model.ExhibitionModel;
import com.zw.yzk.kabu.utils.TimeFormatUtils;

import java.util.ArrayList;
import java.util.List;

import javax.inject.Inject;

/**
 * Created by zhanwei on 2017/2/26.
 */

public class ExhibitionListMapper {

    @Inject
    public ExhibitionListMapper() {

    }

    public ExhibitionModel transfer(ExhibitionListEntity.Item item) {
        ExhibitionModel model = new ExhibitionModel();
        model.setImage(item.coverImage);
        model.setTitle(item.name);
        model.setPlace(item.province + " " + item.city + " " + item.district + " " + item.address);
        model.setBuyable(item.isBuyable == 1);
        model.setId(item.id);
        try {
            model.setDate(TimeFormatUtils.stringDateFormat(item.startTime, "yyyy-MM-dd HH:mm:ss", "yyyy年MM月dd日") + "-"
                    + TimeFormatUtils.stringDateFormat(item.endTime, "yyyy-MM-dd HH:mm:ss", "MM月dd日"));
        } catch (Exception e) {
            model.setDate(item.startTime + "-" + item.endTime);
        }

        return model;
    }

    public List<ExhibitionModel> transfer(List<ExhibitionListEntity.Item> itemList) {
        List<ExhibitionModel> models = new ArrayList<>();
        if (itemList == null || itemList.isEmpty()) {
            return models;
        }
        for (ExhibitionListEntity.Item item : itemList) {
            models.add(transfer(item));
        }

        return models;
    }
}
